package com.jiangjiang.eshop.wms.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jiangjiang.eshop.wms.dto.ReturnGoodsInputOrderApproveDTO;
import com.jiangjiang.eshop.wms.dto.ReturnGoodsInputOrderDTO;
import com.jiangjiang.eshop.wms.dto.ReturnGoodsInputOrderQuery;
import com.jiangjiang.eshop.wms.service.ReturnGoodsInputOrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author Jianghaowen
 * @Date 2021/9/28
 * @Description: TODO
 * @Version V1.0
 **/
@Slf4j
@RestController
@RequestMapping("/wms/returnGoodsInputOrder")
public class ReturnGoodsInputOrderController {
    @Autowired
    private ReturnGoodsInputOrderService returnGoodsInputOrderService;

    /**
     * 保存退货入库单数据
     *
     * @param dto 退货入库单数据
     * @return
     */
    @PostMapping("/save")
    public Boolean saveReturnGoodsInputOrder(@RequestBody ReturnGoodsInputOrderDTO dto) {
        try {
            return returnGoodsInputOrderService.saveReturnGoodsInputOrder(dto);
        }catch (Exception e){
            log.warn("ReturnGoodsInputOrderController saveReturnGoodsInputOrder error",e);
        }
        return false;
    }


    /**
     * 分页查询
     *
     * @param query 分页查询条件
     * @return 查询结果
     */
    @PostMapping("/queryForPage")
    public Page<ReturnGoodsInputOrderDTO> queryForPage(@RequestBody ReturnGoodsInputOrderQuery query) {
        try {
            return returnGoodsInputOrderService.queryForPage(query);
        }catch (Exception e){
            log.warn("ReturnGoodsInputOrderController queryForPage error",e);
        }
        return null;
    }

    /**
     * 根据退货入库单id查询退货入库单数据
     *
     * @param returnGoodsInputOrderId 退货入库单id
     * @return 查询结果
     */
    @GetMapping("/queryById")
    public ReturnGoodsInputOrderDTO queryById(@RequestParam("returnGoodsInputOrderId") Long returnGoodsInputOrderId) {
        try {
            return returnGoodsInputOrderService.queryById(returnGoodsInputOrderId);
        }catch (Exception e){
            log.warn("ReturnGoodsInputOrderController queryById error",e);
        }
        return null;
    }

    /**
     * “
     * 退货入库单更新
     *
     * @param dto 退货入库单
     * @return 处理结果
     */
    @PostMapping("/update")
    public Boolean updateReturnGoodsInputOrder(@RequestBody  ReturnGoodsInputOrderDTO dto) {
       try {
           return returnGoodsInputOrderService.updateReturnGoodsInputOrder(dto);
       }catch (Exception e){
           log.warn("ReturnGoodsInputOrderController updateReturnGoodsInputOrder error",e);
       }
        return false;
    }


    /**
     * 批量保存上架明细数据
     *
     * @param returnGoodsInputOrder 退货入库单数据
     */
    @PostMapping("/batchSavePutOnItems")
    public Boolean batchSavePutOnItems(@RequestBody ReturnGoodsInputOrderDTO returnGoodsInputOrder) {
        try {
            return returnGoodsInputOrderService.batchSavePutOnItems(returnGoodsInputOrder);
        }catch (Exception e){
            log.warn("ReturnGoodsInputOrderController batchSavePutOnItems error",e);
        }
        return false;
    }



    /**
     * 退货入库单提交申请
     *
     * @param returnGoodsInputOrderId 退货入库单id
     * @return c处理结果
     */
    @PostMapping("/submitApprove/{id}")
    public Boolean submitApprove(@PathVariable("id") Long returnGoodsInputOrderId) {
        try {
            return returnGoodsInputOrderService.submitApprove(returnGoodsInputOrderId);
        }catch (Exception e){
            log.warn("ReturnGoodsInputOrderController submitApprove error",e);
        }
        return false;
    }


    /**
     * 退货入库单审核
     *
     * @param dto 参数
     * @return 处理结果
     */
    @PostMapping("/approve")
    public Boolean approve(ReturnGoodsInputOrderApproveDTO dto) throws Exception {
        try {
            return returnGoodsInputOrderService.approve(dto.getReturnGoodsInputOrderId(), dto.getApproveResult());
        }catch (Exception e){
            log.warn("ReturnGoodsInputOrderController approve error",e);
        }
        return false;
    }
}
